<?php
use think\Config;
use think\Request;
/**
 *  @file : rydb.php
 *  @brief: SqlServer数据库配置
 */
return call_user_func(function() {
    $retn = [];
    $host = IS_CLI ? '' : Request::instance()->host(true);
    $name = basename(__FILE__, '.php');
    $cons = [
        'yy'=>[
          'hostname'  => '8.136.120.171',
          'username'  => 'sa',
          'password'  => 'ANgo5023..',
          'hostport'  => '1433',
      ],
    ];
  $dbkv = [
    'accounts'      => 'QPAccountsDB',
    'gameuser'      => 'QPGameUserDB',
    'serverinfo'    => 'QPServerInfoDB',
    'treasure'      => 'QPTreasureDB',
    'treasure'      => 'QPTreasureDB',
    'websms'        => 'CYWebSMSDB',
  ];

  foreach($cons as $range=>$conf) {
    $arr = [];
    foreach($dbkv as $AliasName=>$DbName) {
      $arr[$AliasName] = array_merge([
        'type'      => IS_WIN ? 'sqlsrv' : 'dblib',
        'database'  => '',
        'hostport'  => 1433,
        'debug'     => 1,
        'auto_timestamp'  => 'datetime',
        'datetime_format' => 'Y-m-d H:i:s',
      ], ['database'=>$DbName], $conf);
    }
    Config::set($name, $arr, $range);  // 写进作用域
  }
  
  $alias = array_keys($cons);
  list($hh) = explode('.', $host);
  if (in_array($hh, $alias)) {
    $range = $hh;
  } else {
    $range = $alias[0];
  }
  $retn = Config::get($name, $range);
  return $retn;
});
